package com.xnyzc.lhy.finance.service.impl.config;

import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.finance.entity.config.OaSysCashWithdrawalConfig;
import com.xnyzc.lhy.finance.mapper.config.OaSysCashWithdrawalConfigMapper;
import com.xnyzc.lhy.finance.service.config.IOaSysCashWithdrawalConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 提现规则 服务实现类
 * </p>
 *
 * @author cuixiaojian
 * @since 2019-10-23
 */
@Service
public class OaSysCashWithdrawalConfigServiceImpl extends ServiceImpl<OaSysCashWithdrawalConfigMapper, OaSysCashWithdrawalConfig> implements IOaSysCashWithdrawalConfigService {

    @Autowired
    private OaSysCashWithdrawalConfigMapper oaSysCashWithdrawalConfigMapper;

    /**
     * 根据司机ID获取提现规则
     * @param driverId 司机ID
     * @return Rv
     */
    @Override
    public OaSysCashWithdrawalConfig getCashWithdrawalConfig(Long driverId) {

        OaSysCashWithdrawalConfig oaSysCashWithdrawalConfig = null;
        try {
            oaSysCashWithdrawalConfig = oaSysCashWithdrawalConfigMapper.queryCashWithdrawalConfig(driverId);
        } catch (Exception e) {
            throw PangException.create(EErrorCode.notConfigured);
//            oaSysCashWithdrawalConfig.setFreezePeriod(3);
//            oaSysCashWithdrawalConfig.setMaxPrice(BigDecimal.valueOf(500));
//            oaSysCashWithdrawalConfig.setMaxNumPerDay(1);
//            return oaSysCashWithdrawalConfig;
        }
        if (CheckUtil.objIsEmpty(oaSysCashWithdrawalConfig)) {
            throw PangException.create(EErrorCode.notConfigured);
//            config.setFreezePeriod(3);
//            config.setMaxPrice(BigDecimal.valueOf(500));
//            config.setMaxNumPerDay(1);
//            return oaSysCashWithdrawalConfig;
        }
        return oaSysCashWithdrawalConfig;
    }
}
